package common.service.base.common;

import common.service.util.BeanToMapUtil;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

public class ReqVo {
	private ReqHeader header;
	private Map<String,Object> data;
	
	public Map<String, Object> getData() {
		return data;
	}
	public void setData(Map<String, Object> data) {
		this.data = data;
	}

	public ReqVo(){
		data = new HashMap<String,Object>();
	}
	
	public ReqHeader getHeader() {
		return header;
	}
	public void setHeader(ReqHeader header) {
		this.header = header;
	}
	/***
	 * 设置接收数据
	 * @param name
	 * @param value
	 */
	public void setValue(String name,Object value) {
		if(data!=null){
			data.put(name, value);
		}
	}
	/**
	 * 获取数据
	 * @param name
	 * @return
	 */
	public Object getValue(String name){
		if(data!=null){
			return data.get(name);
		}
		return null;
	}
	
	public Object getObject(String name){
	if(data!=null){
		return data.get(name);
	}
	return null;
	}
	
	public <T> Object getObject(Class<T> tClass){
		try {
			return BeanToMapUtil.convertMap(tClass,this.data);
		} catch (IntrospectionException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
}
